package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.Products;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.page.ProductsQuery;
import com.by.page.SelectedProductsQuery;
import com.by.service.ProductsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Api(tags = "产品管理")
@RequestMapping("/api")
@CrossOrigin
public class productsController extends BaseController {

    @Autowired
    ProductsService productsService;

    @ApiOperation("产品列表")
    @PostMapping("/product")
    public ResultBean query(@RequestBody ProductsQuery query){
        PageBean pageBean = productsService.queryByMap(BeanUtil.beanToMap(query));
        return success("产品列表",pageBean);
    }

    @ApiOperation("已选产品")
    @PostMapping("/product/selected")
    public ResultBean querySelectedProducts(@RequestBody List<String> query){
        List<Products> selectedProducts = productsService.querySelectedProducts(query);
        return success("已选产品",selectedProducts);
    }

    @ApiOperation("产品分类")
    @GetMapping("/product/query")
    public ResultBean queryCategoryById(int id){
        Products category = productsService.queryProductById(id);
        return success("产品分类",category);
    }
}
